package com.htbb.common.util;

import java.util.Random;

/**
 * 获取主键值类
 * @author wangzhicheng
 *
 */
public class AidCreator {
    public enum AidType {
        INSURE_MUTUAL, INSURE_COMMON, PROD, OTHER
    }

    public static long getUcAid(Long custAid){
        String suffix = "999";
        if(custAid!=null){
            String s = String.valueOf(custAid);
            if (s.length()<=3){
                suffix =  s;
            }else{
                suffix =  s.substring(s.length()-3);
            }
        }
        return Long.valueOf(System.currentTimeMillis() + suffix);
    }

    public static long get() {
        return get(AidType.OTHER,null);
    }

    public static long get(AidType type) {
        return get(type,null);
    }

    public static long get(AidType type,Integer seq) {
        String suffix = "9800";
        switch (type) {
            case INSURE_MUTUAL:
                suffix = "7100";
                break;
            case INSURE_COMMON:
                suffix = "0200";
                break;
            case OTHER:
                suffix = randomCreator(3);
                break;
        }
        return Long.valueOf(System.currentTimeMillis() + (seq==null?"":seq+"")  + suffix);
    }

    public static String randomCreator(int length) {
        Random random = new Random();

        String result = "";
        for (int j = 0; j < length; j++) {
            int intChar = random.nextInt(10);
            result += String.valueOf(intChar);
        }

        return result;
    }
}
